import { DailyListNormal } from "./DailyListNormal";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ActiveDegreeRewardList } from "../reward/ActiveDegreeRewardList";
import { DailyItem } from "../item/DailyItem";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { DailyActionDegreeItem } from "../item/DailyActionDegreeItem";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFormat } from "../../../../common/GTextFormat";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { BaseProgressBar } from "../../common/BaseProgressBar";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { StaticResUrl } from "../../../resource/StaticResUrl";
import { SWFInfo } from "../../../../../com/gengine/resource/info/SWFInfo";
type int = number;
//class DailyActiveDegreeList
    
    export  class DailyActiveDegreeList extends DailyListNormal
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onGetItemBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyDegreeGetRewardTotal));
            return;
        }

        /* internal  */onGetItemBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyDegreeGetRewardTotal, true));
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _bg.width = _listWidth;
            _bg.height = _listHeight;
            this.createProcess();
            return;
        }

        protected /* override */ initWidth(): void
        {
            _listWidth = 360;
            _listHeight = 370;
            return;
        }

        protected /* override */ createTitleBar(): void
        {
            return;
        }

        protected /* override */ createListBody(): void
        {
            super.createListBody();
            _scrollPane.y = 2;
            _scrollPane.height = _listHeight - 4;
            _scrollPane.width = _listWidth - 6;
            return;
        }

        protected /* override */ createAwardList(): void
        {
            _dailyAwardList = new ActiveDegreeRewardList(width - _listWidth - 4, _listHeight);
            _dailyAwardList.x = _listWidth + 4;
            _dailyAwardList.y = 0;
            addChild(_dailyAwardList);
            return;
        }

        protected /* override */ onItemListClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as DailyItem;
            if (loc1 && !(loc1 == _lastItem)) 
            {
                loc1.mouseDown(true);
                if (_lastItem) 
                {
                    _lastItem.mouseDown(false);
                }
                _lastItem = loc1;
            }
            return;
        }

        public /* override */ updateData(arg1: Array<any>, arg2: int, arg3: int=0): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            this.dispose();
            if (arg1 != null) 
            {
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    loc3 = arg1[loc1];
                    loc4 = ObjectPool.getObject(DailyActionDegreeItem);
                    if (loc3 != null) 
                    {
                        loc4.updateData(loc3);
                        _bodySprite.addItem(loc4);
                        if (loc1 == 0) 
                        {
                            loc4.mouseDown(true);
                            _lastItem = loc4;
                        }
                    }
                    ++loc1;
                }
                if (loc2 <= 9) 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.OFF;
                }
                else 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
                }
            }
            _bodySprite.redraw();
            _scrollPane.refreshPane();
            _scrollPane.update();
            _scrollPane.horizontalScrollPosition = 0;
            this._degreeBar.setValue(Cache.instance.daily.totalProcess, Cache.instance.daily.maxProcess);
            (_dailyAwardList as ActiveDegreeRewardList).updateProcess();
            if (Cache.instance.daily.hasCanGetProcess()) 
            {
                this._getItemBtn.enabled = true;
            }
            else 
            {
                this._getItemBtn.enabled = false;
            }
            selectedItemByType(arg3);
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            this.stopRewardFly();
            return;
        }

        protected createProcess(): void
        {
            this._getItemBtn = new GButton();
            this._getItemBtn.setSize(80, 22);
            this._getItemBtn.styleName = "ButtonSpecial3";
            this._getItemBtn.setStyle("textFormat", new GTextFormat("", 12, 16187136));
            this._getItemBtn.label = Language.getString(20424);
            this._getItemBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._getItemBtn.x = 527;
            this._getItemBtn.y = _listHeight + 5;
            this._getItemBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetItemBtnClickHandler);
            addChild(this._getItemBtn);
            this._degreeBar = new BaseProgressBar(ImagesConst.ProgressBarBg);
            this._degreeBar.setSize(370, 14);
            this._degreeBar.isScale = true;
            this._degreeBar.progressBarClass = ImagesConst.EnergyBar;
            this._degreeBar.setProgressPosition(8, 3);
            this._degreeBar.x = 145;
            this._degreeBar.y = 382;
            this.addChild(this._degreeBar);
            LoaderManager.instance.load(StaticResUrl.DailyDegreeFont, this.onDegreeFontLoaded);
            return;
        }

        /* internal  */onDegreeFontLoaded(arg1: SWFInfo): void
        {
            if (arg1 && arg1.clip) 
            {
                this._degreeFont = arg1.clip;
                this._degreeFont.x = 15;
                this._degreeFont.y = 378;
                addChild(this._degreeFont);
            }
            return;
        }

        public updateReward(arg1: Array<any>): void
        {
            (_dailyAwardList as ActiveDegreeRewardList).updateReward(arg1);
            return;
        }

        public onGetRewardRes(arg1: Array<any>): void
        {
            (_dailyAwardList as ActiveDegreeRewardList).onGetRewardRes(arg1);
            return;
        }

        public stopRewardFly(): void
        {
            (_dailyAwardList as ActiveDegreeRewardList).stopRewardFly();
            return;
        }

        public updateAcitvityActive(arg1: Boolean, arg2: int): void
        {
            if (arg2 <= 0) 
            {
                if (this._getItemBtn2 && this._getItemBtn2.parent) 
                {
                    removeChild(this._getItemBtn2);
                }
                this._degreeBar.setSize(370, 14);
                this._getItemBtn.x = 527;
            }
            else 
            {
                this._degreeBar.setSize(330, 14);
                this._getItemBtn.x = 490;
                if (!this._getItemBtn2) 
                {
                    this._getItemBtn2 = new GButton();
                    this._getItemBtn2.setSize(80, 22);
                    this._getItemBtn2.styleName = "ButtonSpecial3";
                    this._getItemBtn2.setStyle("textFormat", new GTextFormat("", 12, 16187136));
                    this._getItemBtn2.label = Language.getString(20944);
                    this._getItemBtn2.textField.filters = [FilterConst.nameGlowFilter];
                    this._getItemBtn2.x = this._getItemBtn.x + this._getItemBtn.width + 10;
                    this._getItemBtn2.y = this._getItemBtn.y;
                    this._getItemBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onGetItemBtn2ClickHandler);
                }
                if (!this._getItemBtn2.parent) 
                {
                    addChild(this._getItemBtn2);
                }
                if (arg1) 
                {
                    this._getItemBtn2.enabled = false;
                }
                else if (arg2 <= Cache.instance.daily.totalProcess) 
                {
                    this._getItemBtn2.enabled = true;
                }
                else 
                {
                    this._getItemBtn2.enabled = false;
                }
            }
            return;
        }

        protected /* var */_infoTxt: Object /* flash.text.TextField */;

        protected /* var */_getItemBtn: GButton;

        protected /* var */_degreeBar: BaseProgressBar;

        protected /* var */_degreeFont: Object /* flash.display.MovieClip */;

        protected /* var */_getItemBtn2: GButton;
    }
